use axum::{extract::Path, Json};
use futures_util::TryStreamExt;
use serde_json::{Value, json};

use crate::{mdb, code };
// 所有集合列表
pub async fn index(Path((url, db)): Path<(String, String)>) -> Result<Json<Value>, Json<Value>>{
    let conn = mdb::connect_db(&url, &db).await?;
    let result = conn.list_collections().await;
    match result {
        Ok(f) => {
            let col = f.try_collect::<Vec<_>>().await;
            match col {
                Ok(p) => code::data(json!(p)),
                Err(e) => code::sys(e.to_string())
            }
        },
        Err(e) => code::sys(e.to_string())
    }
}